<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.augurit.common.system.web.auth.form.LoginUserForm"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ include file="/wf/public/meta_wf.jsp"%>
<%LoginUserForm form=(LoginUserForm)request.getSession().getAttribute("SES_LOGIN_USER"); %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;

 %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>预览许可证书</title>
		         <!-- dwr libs -->
<script type='text/javascript' src="${ctx}/dwr/engine.js"></script>
<script type='text/javascript' src="${ctx}/dwr/util.js"></script>
<script type='text/javascript' src="${ctx}/dwr/interface/FileUploadCntl.js"></script>

<script src="${ctx}/gzcgwsp/resources/js/prototype.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/resources/js/YwGrid.js" type="text/javascript"></script>
<script src="${ctx}/resources/js/aos/tool.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
			.titleCss{
				font-size:200%;
				text-align:center;
				font-weight: bold;
			}
			.titile1Css{
				font-size:350%;
				text-align:center;
				font-weight: bold;
			}
			.justifyCss{
				width:20%;
				text-align:justify;
				text-justify:distribute-all-lines;
				text-align-last:justify;
			}
			.tdCss{
				font-size:130%;
				font-weight: bold;
			}
			.tdcontentCss{
				font-size:200%;
				font-weight: bold;
			}
			.inputNoborder {
			    FONT-SIZE: 25px;
			    FONT-FAMILY: 宋体;
			    BORDER-RIGHT: #FFFFFF 1px solid;
			    BORDER-TOP: #FFFFFF 1px solid;
			    BORDER-LEFT: #FFFFFF 1px solid;
			    BORDER-BOTTOM: #FFFFFF 1px solid;
			}
				.inputNoborder2 {
			    FONT-SIZE: 18px;
			    FONT-FAMILY: 宋体;
			    BORDER-RIGHT: #FFFFFF 1px solid;
			    BORDER-TOP: #FFFFFF 1px solid;
			    BORDER-LEFT: #FFFFFF 1px solid;
			    BORDER-BOTTOM: #FFFFFF 1px solid;
			}
		</style>
		
		<script type='text/javascript' src="${ctx}/dwr/engine.js"></script>
		<script type='text/javascript' src="${ctx}/dwr/util.js"></script>
		<script type='text/javascript' src="${ctx}/dwr/interface/FileUploadCntl.js"></script>
		<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
		<script src="${ctx}/gzcgwsp/resources/js/YwEnterprise.js" type="text/javascript"></script>
		<script src="${ctx}/resources/js/jquery/jquery.js" type="text/javascript"></script>
		<script src="${ctx}/gzcgwsp/shljcz/js/csshljcz.js" type="text/javascript"></script>
		<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
		<script src="${ctx}/resources/components/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
		<script type="text/javascript">  
		var contextpath="<%=basePath%>";
		var fileSavePath=getPathBySystem(); 
		
			function printXkz(){
	       		var url = '${ctx}/dllszy!printcz.action?id=${id}&templateCode=${templateCode}&fileCode=xkz&taskInstDbid=${taskInstDbid}&templateId=561';
	       		window.open(url);
           	}
			function save(){
				var params = $("#xkzsForm").serialize();
				var url="${ctx}/dllszy!saveXkzs.action";
				$.ajax({
					url : url,
					type : "post",
					dataType : "html",
					data : params,
					success : function(msg) {
						if(msg=="true"){
							alert('保存成功!');									
						}else{
							alert('保存失败！');
						}							
					},
					error:function() {
						alert("添加失败！请刷新重试！");
					}
				});
			}
		
		//根据操作系统用不同的路径
		function getPathBySystem(){
		     var path="";
		     var ua = navigator.userAgent.toLowerCase();
		     if(ua.indexOf("linux")>=0){
		        path="/usr/local/temp";
		     }else{
		        path="C:\\TEMP\\";
		     }
		    return path;
		}
		
		//盖章按钮
        function gzJyxkzs(){
			var params = $("#xkzsForm").serialize();
			var url="${ctx}/dllszy!checkXkzs.action";
				$.ajax({
					url : url,
					type : "post",
					dataType : "html",
					data : params,
					success : function(msg) {
						if(msg != ""){
							document.getElementById("templateFilePath").value = msg;
							var chinesename = document.getElementById("zydw").value+
           					document.getElementById("acceptNo").value+"许可证.doc";
				           	var filepath=contextpath+"/"+document.getElementById("templateFilePath").value;
				  		   	var filename = filepath.substring(filepath.lastIndexOf("/")+1);
				  		   	TransUpload(filename,chinesename,filepath)
						}else{
							alert('请先制作许可证再盖章！');
						}							
					},
					error:function() {
						alert("添加失败！请刷新重试！");
					}
				});
        }
    
		function TransUpload(result,chinesename,filepath){
			var newpath=MakeWord(result,chinesename,filepath);// 打开word ，把它保存在D盘，相当于下载
			var DocName, CebName, LogName, IniName;
			var DocNameLen;
			var DocNameWONLen;
			var cebtail;
		//	DocName = NewDocForm.OriginalFile.value;
		 	DocName =newpath;
			DocNameLen = DocName.length;
			DocNameWONLen = DocName.lastIndexOf(".") - 1;
			if (DocNameWONLen == -1){
				DocNameWONLen = DocNameLen;
			}else{
				cebtail = DocName.substring(DocNameWONLen+2, DocNameLen);
			}
			if (cebtail.toLowerCase() == "ceb"){
				CebName = DocName;
			}else{
				CebName = DocName.substring(0, DocNameWONLen+1) + ".ceb";
			}
			
			LogName = DocName.substring(0, DocNameWONLen+1) + ".log";
			IniName = DocName.substring(0, DocNameWONLen+1) + ".ini";
			if (DocName != CebName){
				if (!(transMaker(DocName, CebName, LogName, IniName))){// 格式转换
					alert("格式转换失败，请重试！");
					return false;
				}		
			}
			else{
				alert("当前格式为ceb格式！");
			}
			var f=newpath.substring(0,newpath.lastIndexOf("."))+".ceb";
			Stamp_onclick(f);//盖章
			if(ieflag){
			 	//document.getElementById("t1").value=f;
				//callSet(fileTitle);//上传
				Ext.getBody().mask("附件上传中");
		 		fileupload(f,'${id}','${templateCode}',chinesename);
		  }else{
		 	Ext.getBody().mask("附件上传中");
		 	fileupload(f,'${id}','${templateCode}',chinesename);
		  }
			return true;

		}
		//格式转换
		function transMaker(DocName, CebName, LogName, IniName){
			var DTracker;
			DTracker = new ActiveXObject("MakerCom.MakerExt.1");
			var nRet;
			var Error;
			//alert("正转换文件，请稍候......");		
			nRet = DTracker.BeginMaker("");
			if (nRet != 0){
				alert(DTracker.GetErrorMessage(nRet));		
				delete DTracker;
				return false;
			}		
		    //alert("开始文档格式转换......请稍后!");		
			nRet = DTracker.SingleFileConvert(DocName, CebName, "标准模板", LogName, IniName);	
			if (nRet != 0){
				alert("MakerOcx transfer error!");
				nRet = DTracker.EndMaker();		
				delete DTracker;
				return false;
			}
			nRet = DTracker.EndMaker();
			if (nRet != 0){
				alert("MakerOcx End error!");		
				delete DTracker;
				return false;
			}	
			alert("格式转换完成！");	
			delete DTracker;
			return true;
		}
		//文件保存到本地
		 function MakeWord(filename,chinesename,filepath){
	        var WordApp=new ActiveXObject("Word.Application");
	        var newpath=fileSavePath+chinesename;
	        WordApp.Application.Visible=false; 
	        WordApp.NormalTemplate.Saved = true;
	        var  templatecode="${templateCode}";
	        var url=filepath;
	        var Doc=WordApp.Documents.Add(url,false);
	        Doc.saveAs(newpath);
	        Doc.Close();
	        WordApp.Quit();
	        return newpath;
 		}
		
		function upload(){
			var attache = dwr.util.getValue('f1');
			var uploadName=dwr.util.getValue('f1').value;
			if (uploadName == '') { 
			     uploadName=$('t1').value;
			}
			var ajid='${id}';
			var username='<%=form.getUser().getUserName() %>';
			//var dotIndex =uploadName.lastIndexOf(".");
			//if (dotIndex < 0) dotIndex = uploadName.length;
			var attacheName = document.getElementById("zydw").value+
           					document.getElementById("acceptNo").value+"许可证";
			var attacheType = ".doc";
			var obj;	
			 obj ={
			  ajid:ajid,
			  username:username,
			  filename:attacheName,
			  filetype:attacheType
			  };	
				
			var params=Ext.encode(obj);
			FileUploadCntl.uploadDzgz(params, attache, function (result){
			       Ext.Msg.alert("提示!","上传成功!");
			       //viewStore.load();
			});
		}
		
		function set1(){
		    //将text1中的值复制到剪贴板中
		    window.clipboardData.setData('text',$("#t1").val()); 
		    //创建Shell(需要添加到信任站点或解除未签名的ActiveX控件的禁用
		    var   WshShell=new   ActiveXObject("WScript.Shell"); 
		    //拿到焦点
		    $("#f1").focus();
		    //Ctrl + A 操作
		    WshShell.sendKeys("^a");
		    //Ctrl + V 操作(sendKeys对于中文赋值操作显得无力,所以只能模拟键盘操作)
		    WshShell.sendKeys("^v");
		}

		//给当前网页中四个file对象赋值的方法
		function set(){
		    //此处不要用循环,有几个就需要写几个setXX方法
		    setTimeout("set1()",1000);
		    setTimeout("upload()",2000);
		}
		//检查是否赋值成功
		function check(){
		    //检查每个file对象是否为空 
		    var aa = document.getElementById("f1").value;
		    alert(aa);
		    if($('f1').value.length > 0){
		        //检查原对象的值的赋值对象的值是否相同
		        if($('f1').value == $('t1').value){
		            return true;
		        }else{
		            return false;
		        }
		    }else{
		        return false;
		    }
		}
		//赋值和file对象的检查
		function setValues(){
		    //if(!check()){
		        set();
		    //}
		}
		//直接调用的赋值方法
		function callSet(){
		    //一定要用setInterval,而不能用循环(循环太快,会造成所有的值赋在一个file对象上)
		    //setInterval('setValues()',1000);
		    setValues();    
		}
        </script>
        <script language="vbs">
Function Stamp_onclick(strCEBFileName)    	
	Dim strErrMessage, lRet, objStampClientTool,g_AffixRegisterURL,g_SendPrintURL,UnitName
	g_AffixRegisterURL="http://172.16.253.169/StampServer/interfaces/background/AffixRegister.aspx"
	g_SendPrintURL="http://172.16.253.169/StampServer/extend/interfaces/SendPrint.aspx"
	UnitName=""

	lRet = ""
	strErrMessage = ""
	strCEBFileName = trim(strCEBFileName)

	if  0 = len(trim(strCEBFileName)) then
		Call Alert("请选择CEB文件！", vbExclamation, "请选择CEB文件！")
		Exit Function
	else
		if UCase(Right(Trim(strCEBFileName), 3)) <> "CEB" then
			Call Alert("只能选择CEB格式的文件！", vbExclamation, "只能选择CEB格式的文件！")
			CEBFileName.value = ""
			Exit Function
		end if                  	 	  
	end if

	set objStampClientTool  = CreateObject("StampClientTool.StampTool")

	' 本地可视化盖章	
	lRet = objStampClientTool.LocalSealStamp(strCEBFileName, UnitName, g_AffixRegisterURL, g_SendPrintURL)
	
	if lRet <> 0 then
		strErrMessage = objStampClientTool.GetErrorMessage()
        alert "盖章失败原因:" & strErrMessage
	end if

	Set objStampClientTool = Nothing	
End Function

Sub PreviewCEB(xuwei)
	Dim lRet
	lRet = DCreateGBForm1.ViewLocalCEB(xuwei)
End Sub

Sub PreviewNetCEB(xuwei)
	Dim lRet
	lRet = DCreateGBForm1.ViewNetCEB(xuwei)
End Sub

</script>
	</head>
	<body>
		
		<form action="" method="POST" id="xkzsForm">
		<input type="hidden" name="id" value="${id}"/>
		<input type="hidden" id="activityName" value="${hjmc}"/>
		<input type="hidden" id="templateCode" value="${templateCode}"/>
		<input type="hidden" id="taskInstDbid" value="${taskInstDbid}"/>
		<input type="hidden" id="zydw" value="${zydw}"/>
		<input type="hidden" name="curYear" id="curYear" value="${curYear}"/>
		<input type="hidden" id="acceptNo" value="${acceptNo}"/>
		<input type="hidden" name="templateFilePath" id="templateFilePath" value="${templateFilePath}">
			<table width="100%" height="80%" border="0" align="center">
				<tr>
					<td width="40%">
						<table align="center">
							<tr>
								<td>
									<br><br><br>
									<h1 style="font-size:52px" align="center" >
										城市道路人行道<br>及相关公共场地<br>临时占用<br>
										<span style="font-size:68px">许&nbsp;&nbsp;&nbsp;可&nbsp;&nbsp;&nbsp;证</span>
									</h1><br><br><br><br><br><br><br>
								</td>
							</tr>
							<tr>
								<td>
									<h3 align="right">
										编号：
										<u>
											<c:choose>
											  	<c:when test="${fn:contains(templateCode,'qx')}">
													<td bordercolor="#000000" colspan="2" height="150" align="center">区${curYear }-<input name="zsbh" value="${zsbh }" style="border:0;border-bottom:1 solid black;width:30px"/></td>
												</c:when>
												<c:otherwise>
													<td bordercolor="#000000" colspan="2" height="150" align="center">市${curYear }-<input name="zsbh" value="${zsbh }" style="border:0;border-bottom:1 solid black;width:30px"/></td>
												</c:otherwise>
											  </c:choose>
											
										</u>
									</h3>
								</td>
							</tr>
							<tr>
								<td>
									<h3 align="left">
										批准临占期限：
										<u>
											<input style="border:0;border-bottom:1 solid black;width:110px;" type="text" name="zysjqssj" readOnly="true" value="<s:date name='zysjqssj' format='yyyy年MM月dd日'/>" onfocus="WdatePicker({dateFmt:'yyyy年MM月dd日'})" class="textdocWdate" required="true"/>
											&nbsp;至
											<input style="border:0;border-bottom:1 solid black;width:110px;" type="text" name="zysjjssj" readOnly="true" value="<s:date name='zysjjssj' format='yyyy年MM月dd日'/>" onfocus="WdatePicker({dateFmt:'yyyy年MM月dd日'})" class="textdocWdate" required="true"/>
										</u>
									</h3>
								</td>
							</tr>
						</table>					
					</td>
					<td width="40%">
						<table width="100%" border="1" cellspacing="0" cellpadding="2" class="tpl_list_ui">
							<tr height="50px">
								<td colspan="2">临时占用单位：${zydw }</td>
							</tr>
							<tr height="50px">
								<td>负责人：<input name="aqfzr" value="${aqfzr}" style="border:0;"/></td>
								<td>电话：<input name="zydwTel" value="${zydwTel}" style="border:0;"/></td>
							</tr>
							<tr height="50px">
								<td colspan="2">临时占用地点：<input name="zylmld" value="${zylmld}" style="border:0;width:70%"/></td>
							</tr>
							<tr height="50px">
								<td colspan="2">临时占用性质：<input name="zyxz" value="${zyxz}" style="border:0;width:70%"/></td>
							</tr>
							<tr height="50px">
								<td colspan="2">临时占用面积：<textarea name="lszyArea" rows="8" style="border:0; width:100%">${lszyArea}</textarea></td>
							</tr>
							<tr height="50px">
								<td>投诉电话：12319</td>
								<td>发证时间：<input style="border:0;border-bottom:1 solid black;width:110px;" type="text" name="zsrq" readOnly="true" value="<s:date name='zsrq' format='yyyy年MM月dd日'/>" onfocus="WdatePicker({dateFmt:'yyyy年MM月dd日'})" class="textdocWdate" required="true"/></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<table align="center">
				<tr>
					<td>
						<input type="button" id="savezs" onclick="save();" value="保&nbsp;&nbsp;存" style="width:100px;"/> 
					    <input type="button" onclick="printXkz();"  id="printzs" value="制作、打印" style="width:100px;"/>
						<input type="button" onclick="gzJyxkzs();"  id="printzs" value="盖章" style="width:100px;"/>
						<input type="button" onclick="viewJyxkzs();"  id="printzs" value="查看盖章" style="width:100px;"/>
						<input type="button" value="关闭窗口" onclick="window.close();" style="width:100px;"/>
					</td>
				</tr>
		    </table>
		</form>
	</body>
</html>